/**
 * 推广分类
 * @author linfeng
 * @since 2019/12/24
 */
layui.extend({
    zmnExportUtil: '{/}/static/js/zmn.excel.util'
}).define(['index', 'form', 'table', 'laypage', 'layedit','zmnExportUtil'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    var zmnExportUtil =layui.zmnExportUtil;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        defaultToolbar: ['print'],
        page: true,
        limit: json.pageSize,
        height: 'full-149'
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    var ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.categId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        //启用停用
        if (obj.event == "start" || obj.event == "stop") {
            if (ids.length === 0) {
                return layer.alert("请选择至少1个分类！");
            }
            zmnPage.layStartStop(obj, "/extension/serv/category/updateStatus.action", ids.join(","));
        }
        //导出excel
        if(obj.event=='CUSTOM_EXPORT'){
            zmnExportUtil.doExportExcel('zmn-table','推广服务分类');
        }

    });

    // 修改排序和首字母
    table.on("edit(zmn-table)", function (obj) {
        if(obj.field=='sort'){
            zmnPage.laySortPositiveInteger(obj.value,"/extension/serv/category/updateSort.action",obj.data.categId,100000,1000);
        }else if(obj.field=='firstLetter'){
            zmnPage.layFirstLetter(obj.value,"/extension/serv/category/updateFirstLetter.action",obj.data.categId,3,1000);
        }

    });
    $("#table_body").on('click', '.updateClass', function () {
        var $button = $(this);
        var cateId = $button.data('cateid');
        return zmnLayUtil.openIframeCustom(layer, "/extension/serv/category/detail.action?categId="+cateId, {title: "修改服务分类", shade: 0.3, area:["550px", "430px"]});
    });
    //对外暴露的接口
    exports('extension_serv_category_list_js', {});
});

